package offer;

import java.util.Stack;

///包含min函数的栈
public class T21 {
    private Stack<Integer> stack = new Stack<Integer>();
    private Stack<Integer> minStack = new Stack<Integer>();
    public void push(int node) {
        if (stack.empty()) {
            stack.push(node);
            minStack.push(node);
        }else {
            minStack.push(stack.peek()>node?node:stack.peek());
            stack.push(node);
        }
    }

    public void pop() {
          if (!stack.empty()) {
              minStack.pop();
              stack.pop();
          }
    }

    public int top() {
        return stack.peek();
    }

    public int min() {
        return minStack.peek();
    }
}
